#include "widget.h"
#include "ui_widget.h"
#include <QTimer>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //启动定时器
    //id1 = startTimer(1000);
    //id2 = startTimer(2000);
    QTimer * timer = new QTimer(this);
    timer->start(2000); //启动方式

    connect(timer, &QTimer::timeout, [=](){
        static int num = 1;
        ui->label1->setText(QString::number(num++));
    });

}


//定时器事件
void Widget::timerEvent(QTimerEvent * e)
{
    qDebug() << "timer";

}



Widget::~Widget()
{
    delete ui;
}

